#pragma once

#ifndef NULL
#define NULL 0x0
#endif

class PruebaMemoria;

#define MEMORY_BUCKETS 128

class MemoryShare abstract
{
	friend class PruebaMemoria;

public:
	virtual ~MemoryShare();

private:
	struct MemoryUsage
	{
		const char* TypeName;
		unsigned int Contador;
		void* Memoria;
		void (*Liberar)(void* memoria);

		MemoryUsage* NextUsage;
	};

	MemoryUsage* m_Used;

	void IncrementarContador() const;
	void DecrementarContador();
	void LiberarMemoria();

	static void RemoveFromGeneralUse(MemoryUsage* usage);
	static void AddToGeneralUse(MemoryUsage* usage);
	static MemoryUsage* GetFromGeneralUse(void* memoria);

	static MemoryUsage* s_GeneralUse[MEMORY_BUCKETS];
	static MemoryUsage* s_FirstCheck[MEMORY_BUCKETS];

protected:
	MemoryShare(const char* typeName, void* memoria, void (*liberar)(void*));
	MemoryShare(const MemoryShare& m);
	MemoryShare& operator=(const MemoryShare& m);
};
